<template>
    <el-dialog :title="title" :visible.sync="open" :width="dialogWidth" destroy-on-close append-to-body>
        <el-form :model="formData" size="small" label-width="120px" ref="form" v-if="taskData != null">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="任务内容" prop="cate">
                        {{ taskData.taskContent }}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="反馈内容" prop="countText">
                        <el-input type="textarea" v-model="formData.submitContent" :disabled="disabled" placeholder="请输入反馈内容"> </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="24">
                    <el-form-item label="任务附件" prop="location">
                        <uploAding @uploading="onUploaded" :hidden="false"></uploAding>
                        <el-table :data="uploadinglist" border size="mini" width="100%">
                            <el-table-column prop="attachname" label="名称" align="center"> </el-table-column>
                            <el-table-column prop="attachsize" label="大小" align="center"> </el-table-column>
                            <el-table-column prop="attachtype" label="类型" align="center"> </el-table-column>
                            <el-table-column label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button type="text" size="small" @click="remove(scope.$index)"> 移除 </el-button>
                                    <el-button type="text" size="small" @click="downloadFile(scope.row)"> 下载 </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="executeTask">处置完成</el-button>
        </div>
        <task-report-attach ref="taskReportAttach" />
    </el-dialog>
</template>

<script>
import uploAding from "@/views/components/uploAding/index.vue";
import dialogMixin from "@/mixins/dialogMixin";
import TaskReportAttach from "@/views/response/handle/components/TaskReportAttach.vue";
import * as DrillApi from "@/api/drill/drill.js";
import { submitTask } from "@/api/response/task.js";

export default {
    name: "TaskExecuteDialog",
    mixins: [dialogMixin],
    components: {
        uploAding,
        TaskReportAttach,
    },
    props: {
        handClick: {
            type: Function,
        },
    },
    data() {
        return {
            title: "执行任务",
            open: false,
            taskData: null,
            formData: {
                content: "",
                reason: "",
            },
            uploadinglist: [],
            countText: "",
            status: 2,
            disabled: false,
            hidden: false,
            //预案任务提交
            type: 2,
            //详情
            flag: "",
            meettype: "",
            executeType: 3,
            currentGroup: {
                flowId: 1,
                flowTitle: "组建领导小组",
                roleList: [
                    {
                        deptId: 0,
                        userName: "测试",
                    },
                    {
                        deptId: 0,
                        userName: "测试",
                    },
                ],
            },
            responseLevels: [
                {
                    label: "Ⅰ级响应",
                    value: 1,
                },
                {
                    label: "Ⅱ级响应",
                    value: 2,
                },
                {
                    label: "Ⅲ级响应",
                    value: 3,
                },
                {
                    label: "Ⅳ级响应",
                    value: 4,
                },
            ],
            planTitle: "",
            planId: 0,
            responseLevel: 0,
            nickName: "",
            newTasks: [],
            responseLevelOption: [],
            userId: 0,
            nickName: "",
        };
    },
    mounted() {},
    computed: {
        dialogWidth() {
            return "60%";
        },
    },
    methods: {
        //完成任务调
        showDialog(data) {
            this.taskData = data;
            this.formData = {
                content: "",
                reason: "",
            };
            this.uploadinglist = [];
            this.open = true;
        },
        onExecuteTypeChange() {},
        executeTask() {
            // 立即执行任务提交
            let data = {};
            data.submit = this.formData.submitContent;
            data.attachIds = [];
            this.uploadinglist.forEach(a => {
                data.attachIds.push(a.attachid);
            });
            submitTask(this.taskData.id, data).then(res => {
                this.$modal.msgSuccess("任务执行成功");
                this.open = false;
                this.$emit("handleOk");
            });
        },
        onUploaded(data) {
            // 上传文件
            this.uploadinglist.push(data);
        },
        //移除
        remove(index) {
            this.uploadinglist.splice(index, 1);
        },
        downloadFile(row) {
            this.download(`com/ComAttach/download/${row.attachid}`, {}, `${row.attachname}.${row.attachtype}`);
        },
    },
};
</script>

<style lang="scss" scoped>
.task-report {
    padding: 0 20px 20px;
}
</style>
